import $ from '../common';
Page({
  data: {
    titleHeight: $.gData().titleHeight,
    statuHeight: $.gData().statuHeight,
    isIphoneX: $.gData().isIphoneX,
    page: 1,
    info: [],
    tip: '下拉加载更多'
  },
  godecoratehomework(e) {
    const {
      testpaper_uuid,
      status
    } = e.currentTarget.dataset
    const {
      group_uuid
    } = this.data
    $.navigateTo(`/classaboutPart/creatework?group_uuid=${group_uuid}&testpaper_uuid=${testpaper_uuid}&status=${status}`)
  },
  //触底
  onReachBottom() {
    console.log('触底了！！！');
    this.getinfo()
  },
  homebtnhand() { //去往创建
    const {
      group_uuid
    } = this.data
    $.navigateTo(`/classaboutPart/creatework?group_uuid=${group_uuid}&testpaper_uuid=&status=`)
  },
  getinfo() {
    const {page, group_uuid,info} = this.data
    $.get('/teacher/testpaper/list', {
      page,
      limit: 20,
      group_uuid
    }, res => {
      if (res.testpaper.length < 20) {
        this.data.tip = '已经到底了'
      } else {
        this.data.tip = '下拉加载更多'
      }
      this.data.page++
      this.setData({
        info: [...info,...res.testpaper],
        tip: this.data.tip
      })
    })
  },
  onLoad(e) {
    const {
      group_uuid
    } = e
    this.setData({
      group_uuid
    })
  },
  onShow() {
    this.getinfo()
  }
})